/**
 * 背景负责加载地图、飞机、敌人、子弹, 监听加速、攻击按钮事件
 * 
 * author：  suyuyi
 * Date：    2017-4-15
 */
 cc.Class({
    extends: cc.Component,

    properties: {
        
    },

    // use this for initialization
    onLoad: function () {
        this._map = null;
        this.plane = null;
        this.enemy = null;
        this.bullet = null;
        this.resFlag = false;
        this._updateMap();
        cc.loader.loadRes('persist/plane_hero', function(err, prefab){
            var player = cc.instantiate(prefab);
           this.plane = player;
          this.node.addChild(this.plane,1,1001);
        }.bind(this),function(){
            this.resFlag = true;
        }); // TODO：看看 bind 有什么用
        
        this._updatePlane();
        this.node.active = true;
        //this.plane = this.node.getChildByName("plane_hero");
        if(this.resFlag){
            cc.log(this.plane);
        }
        
        //this.joytick = cc.find("joystick", this.node.parent).addComponent("joystick1");
        this.node.on("joystick_move",this._handle,this);
        
        this.btn_attack = cc.find("btn_attack", this.node.parent);
        this.btn_speed = cc.find("btn_speed", this.node.parent);

        this.btn_attack.on(cc.Node.EventType.TOUCH_END, this._touchEnd, this);
        this.btn_attack.on(cc.Node.EventType.TOUCH_CANCEL, this._touchEnd, this);

        this.btn_speed.on(cc.Node.EventType.TOUCH_END, this._touchEnd, this);
        this.btn_speed.on(cc.Node.EventType.TOUCH_CANCEL, this._touchEnd, this);
    },
    _updateMap(){
        this._map = this.node.addComponent("Map1");
    },
    _updatePlane: function(){
        
    },
    getPlane: function(){
        return this.resFlag;
    },
    _updateEnemy(){

    },
    _updateBulltet(){

    }
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
